<!DOCTYPE html>
<html lang="en">
<!--header-->
<include file="Public:header"/>
<!--header-->
<section id="main-content">
    <section class="wrapper">
        <h3><i class="fa fa-angle-right"></i> 添加/修改资讯信息</h3>

        <!-- BASIC FORM ELELEMNTS -->
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb">
                        <i class="fa fa-angle-right"></i> 资讯信息
                        <a class="btn btn-theme btn-default" href="{:U('info',array('type_id'=>$lei['id'],'currpage'=>$currpage))}">返回</a>
                    </h4>

                    <form id="myForm" class="form-horizontal style-form" method="post" action="{:U('adds')}"  enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">资讯类别</label>
                            <div class="col-sm-10">
                                <select  name="type_two_id" class="form-control">
                                    <foreach name="type" item="v">
                                        <option value="{$v.id}" <if condition="$v['id'] == $list['type_two_id']">selected</if> >{$v.name}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                       <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">课程名称</label>
                            <div class="col-sm-10">
                                <select name="ke_id" class="form-control">
                                    <foreach name="video" item="v">
                                        <option value="{$v.id}" <if condition="$v['id'] == $list['ke_id']">selected</if>>{$v.title}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="banner">
                            <label class="col-sm-2 col-sm-2 control-label">资讯图<span style="color: red;">(750px*300px)</span></label>
                            <div class="col-sm-10">
                                <input type="file" name="img" id="avatar" onchange='PreviewImage(this)' style="opacity: 0;display: block;cursor:pointer" />
                                <if condition="$list.img != NULL">
                                    <img class="ph-user"  src="{$list.img}" width="190" height="180" onclick="openFile()" style="cursor:pointer">
                                    <else/>
                                    <img class="ph-user" src="__PUBLIC__/img/wutu.png" alt="" width="190" height="180" onclick="openFile()" style="cursor:pointer">
                                </if>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">联系电话</label>
                            <div class="col-sm-10">
                                <input id="phone" name="phone" value="{$list.phone}" type="text"  maxlength="11" class="form-control" placeholder="请输入手机号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input id="intro"  name="title" value="{$list.title}" type="text"  maxlength="11" class="form-control" placeholder="请输入标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">简介</label>
                            <div class="col-sm-10">
                                <input  name="intro" value="{$list.phone}" type="text"  maxlength="11" class="form-control" placeholder="请输入简介">
                            </div>
                        </div>
                        <div id="contents" class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">资讯详情</label>
                            <div class="col-sm-10">
                                <textarea  name="content" class="input">{$list.content}</textarea>
                            </div>
                        </div>
                        <input type="hidden"  name="id" value="{$list.id}">
                        <input type="hidden"  name="imgs" value="{$list.img}">
                        <input type="hidden" name="currpage" value="{$currpage}">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                                <input  type="button" id="tianjia" class="btn btn-theme" value="保存" style="width: 150px;">
                                <input  type="reset" class="btn btn-warning" value="重置" style="width: 150px">
                            </div>
                        </div>
                    </form>
                </div>
            </div><!-- col-lg-12-->
        </div><!-- /row -->
    </section>
</section>
<!--footer-->
<include file="Public:footer"/>
<!--footer-->
<script type="text/javascript" src="__PUBLIC__/ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="__PUBLIC__/kindeditor/lang/zh_CN.js"></script>
<script>
    //编辑器
    var editor;
    KindEditor.ready(function(e){
        editor = e.create("[name=content]",{
            "width":"700px",
            "height":"300px",
            allowFileManager:true, //允许对上传图片进行管理
            "items":["source", "|", "undo", "redo", "|", "preview","|", "justifyleft", "justifycenter", "justifyright", "justifyfull", "insertorderedlist", "insertunorderedlist", "indent", "outdent", "subscript", "superscript", "clearhtml","|","formatblock", "fontname", "fontsize", "|", "forecolor", "hilitecolor", "bold", "italic", "underline","|", "image"]
        });
    });
    $("#tianjia").click(function(){
        editor.sync();
        var intro    = $("#intro").val();
        var phone   = $("#phone").val();
        var re=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!re.test(phone)){
            layer.alert('请输入正确的手机号码。');
            return false;
        }
        if(intro == '' || phone == ''){
            layer.open({
                title: '添加/修改提示：',content: '资讯信息请填写完整'
            });
        }else{
            $("#myForm").submit();
        }
    });
    //图片上传
    function openFile(){
        return  $("#avatar").click();
    }

    function PreviewImage(imgFile)
    {
        var filextension=imgFile.value.substring(imgFile.value.lastIndexOf("."),imgFile.value.length);
        var o=imgFile.files[0];
        filextension=filextension.toLowerCase();
        if ((filextension!='.jpg')&&(filextension!='.jpeg')&&(filextension!='.png')&&(filextension!='.bmp')) {
            imgFile.focus();
        }else if(o.size > 2097152){
            imgFile.focus();
        } else {
            var path;
            path=window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
            $('.ph-user').attr({src:path});
        }
    }
</script>

</body>
</html>


